
/* This is my program for adapting the */
/* structural estimation to our paper  */

clear

insheet using "F:\Dropbox\Research\James_Ryan_Miriam_\data\replication\form13f.csv"
rename cik filer_cik
sort filer_cik

merge 1:m filer_cik using f:\filer_cik
tab _merge
gen file13f=0
replace file13f=1 if _merge==3
drop if _merge==1
des
drop _merge
sort filer_cik
save temp,replace

clear
insheet using "F:\Dropbox\Research\James_Ryan_Miriam_\data\replication\type.csv"
rename cik filer_cik
sort filer_cik
quietly by filer_cik:  gen dup = cond(_N==1,0,_n)
tab dup
drop if dup>1
drop dup
sort filer_cik

merge 1:m filer_cik using temp
drop if _merge==1

tab _merge 
drop _merge

replace type="oth" if type==""
encode type,gen(subtype)

tab type
tab subtype


outsheet filer_cik file13f subtype using "F:\Dropbox\Research\James_Ryan_Miriam_\data\replication\subsamples.csv",c replace nolab

